﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LINQPad.OpenAccess.Data
{
    /// <summary>
    /// DbProviderData
    /// </summary>
    public sealed class DbProviderData : IEquatable<DbProviderData>
    {
        #region Public

        #region - Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="DbProviderData" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        /// <param name="invariantName">Name of the invariant.</param>
        public DbProviderData( string name, string description, string invariantName )
        {
            this.Name = name ?? String.Empty;
            this.Description = description ?? String.Empty;
            this.InvariantName = invariantName ?? String.Empty;
        }

        #endregion

        #region - Properties

        /// <summary>
        /// Gets the name.
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        public string Name { get; private set; }
        /// <summary>
        /// Gets the description.
        /// </summary>
        /// <value>
        /// The description.
        /// </value>
        public string Description { get; private set; }
        /// <summary>
        /// Gets the name of the invariant.
        /// </summary>
        /// <value>
        /// The name of the invariant.
        /// </value>
        public string InvariantName { get; private set; }

        #endregion

        #endregion

        #region Object Members

        /// <summary>
        /// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals( object obj )
        {
            return this.Equals( obj as DbProviderData );
        }
        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode( )
        {
            return StringComparer.InvariantCulture.GetHashCode( this.InvariantName );
        }
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString( )
        {
            return this.InvariantName;
        }

        #endregion

        #region IEquatable<DbProviderData> Members

        /// <summary>
        /// Determines whether this instance is logically equal to the specified other one.
        /// </summary>
        /// <param name="other">The other.</param>
        /// <returns>
        ///   <c>true</c> if equal; otherwise, <c>false</c>.
        /// </returns>
        public bool Equals( DbProviderData other )
        {
            if ( other == null )
                return false;
            return String.Equals( this.InvariantName, other.InvariantName );
        }

        #endregion
    }
}
